package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.excel.OneSubject;
import com.atguigu.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author hwt
 * @since 2022-08-21
 */

@Api(tags = {"excel 表格上传"})
@RestController
// “/dev-api/” 是前端的那个统一前缀，我没去除所以这里也要加上
@RequestMapping("eduservice/subject")
@CrossOrigin // 解决跨域问题
public class EduSubjectController {

    @Resource
    EduSubjectService subjectService;

    /**
     * 根据 excel 构建分类
     * @param file
     * @return
     */
    @PostMapping("/addSubject")
    public R addSubject(@RequestParam("file") MultipartFile file){

       return subjectService.saveSubject(file,subjectService);

    }

    @GetMapping("getAllSubject")
    public R getAllSubject(){
        //list集合泛型是一级分类，因为一级分类有他本身和二级分类的集合
        List<OneSubject> list= subjectService.getAllOneTwoSubject();
        return R.ok().data("children",list);
    }

}

